package com.ruoyi.washer.service.impl;

import java.util.List;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.washer.mapper.XwWashballMapper;
import com.ruoyi.washer.domain.XwWashball;
import com.ruoyi.washer.service.IXwWashballService;

/**
 * 洗衣球Service业务层处理
 *
 * @author hawking
 * @date 2023-12-15
 */
@Service
public class XwWashballServiceImpl implements IXwWashballService
{
    @Autowired
    private XwWashballMapper xwWashballMapper;

    /**
     * 查询洗衣球
     *
     * @param washballId 洗衣球主键
     * @return 洗衣球
     */
    @Override
    public XwWashball selectXwWashballByWashballId(Long washballId)
    {
        return xwWashballMapper.selectXwWashballByWashballId(washballId);
    }

    /**
     * 查询洗衣球列表
     *
     * @param xwWashball 洗衣球
     * @return 洗衣球
     */
    @Override
    public List<XwWashball> selectXwWashballList(XwWashball xwWashball)
    {
        return xwWashballMapper.selectXwWashballList(xwWashball);
    }

    /**
     * 新增洗衣球
     *
     * @param xwWashball 洗衣球
     * @return 结果
     */
    @Override
    public int insertXwWashball(XwWashball xwWashball)
    {
        return xwWashballMapper.insertXwWashball(xwWashball);
    }

    /**
     * 修改洗衣球
     *
     * @param xwWashball 洗衣球
     * @return 结果
     */
    @Override
    public int updateXwWashball(XwWashball xwWashball)
    {
        return xwWashballMapper.updateXwWashball(xwWashball);
    }

    /**
     * 批量删除洗衣球
     *
     * @param washballIds 需要删除的洗衣球主键
     * @return 结果
     */
    @Override
    public int deleteXwWashballByWashballIds(Long[] washballIds)
    {
        return xwWashballMapper.deleteXwWashballByWashballIds(washballIds);
    }

    /**
     * 删除洗衣球信息
     *
     * @param washballId 洗衣球主键
     * @return 结果
     */
    @Override
    public int deleteXwWashballByWashballId(Long washballId)
    {
        return xwWashballMapper.deleteXwWashballByWashballId(washballId);
    }
    public JSONObject getAgentWashballList(String openId){
        JSONObject jsonObject=new JSONObject();
        XwWashball xwWashball=new XwWashball();
        xwWashball.setAgentOpenId(openId);
        List<XwWashball> xwWashballList=xwWashballMapper.selectXwWashballListByAgent(xwWashball);
        if(xwWashballList==null||xwWashballList.size()==0){
            jsonObject.put("ballcount",0);
        }else{
            jsonObject.put("ballcount",xwWashballList.size());
        }
        jsonObject.put("xwWashballList",xwWashballList);
        return jsonObject;
    }
}
